package com.lanmon.sqlite;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.dbutils.ResultSetHandler;

import com.lanmon.pojo.Exam;

public class ExamResultSetHandler implements ResultSetHandler<Exam> {
	
	@Override
	public Exam handle(ResultSet rs) throws SQLException {
		if (rs != null) {
			List<Exam> list = new ArrayList<>();
			while (rs.next()) {
				Exam exam = new Exam();
				exam.setAnswer(rs.getString("answer"));
				exam.setBody(rs.getString("body"));
				exam.setId(rs.getInt("id"));
				exam.setTitle(rs.getString("title"));
				list.add(exam);
			}
			return list.size() == 1 ? list.get(0) : null;
		}
		return null;
	}
	
}
